<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String username = "";
    String password = "";
    Cookie[] cookies = request.getCookies();
    if (cookies!=null){
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if ("username".equals(cookie.getName())){
                username = cookie.getValue();
            }
            if ("password".equals(cookie.getName())){
                password = cookie.getValue();
            }
        }
    }

    String code = (String) request.getAttribute("code");
%>
<!doctype html>
<html>
<head>
    <meta charset='utf-8'>
    <title>后台管理员登录</title>
    <link rel="stylesheet" href="../css/loginStyle.css">
    <script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="../js/sweetalert.min.js"></script>
</head>
<body>
<div class="box">
    <div class="registerdiv">
        <a href="./register.html" style="color: white" >注册 </a>
    </div>
    <h2>管理员登录</h2>
    <form action="./user.do" method="post">
        <input type="hidden" name="action" value="login">
        <div class="inputBox">
            <input type="text" name="username" value='<%=username==null?"":username%>'>
            <label>用户名：</label>
        </div>
        <div class="inputBox">
            <input type="password" name="password" value="<%=password==null?"":password%>" >
            <label>密码：</label>
        </div>
        <div>
            <input type="checkbox" class="remember-input" value="remember-me" name="remeberMe"><label class="remember-lb">记住我</label>
        </div>
        <input type="submit" name="" value="登录">
        <input type="button" value="游客登录">
    </form>

</div>

</body>
<script type="text/javascript">
    $(function () {
        <%
            if ( !("".equals(username)) && username != null && !("".equals(password)) && password != null ){
                %>
        $('input:checkbox').attr("checked","checked");
        <%
            }
        %>

        <%
            if ("-1".equals(code)){
        %>
            swal({
                title:'登录失败',
                icon:'error',
                text:'用户名密码有误',
                confirmButtonText: "确定",
            }).then(function () {
                window.location.href = "./login.jsp"
            })
        <%
            }
         %>

        $('input[name = "password"]').on('change',function () {
            $.ajax({
                async:true,
                url:"./user.do?action=login",
                data:{"flagpassword":$('input[name = "password"]').val()},
                dataType:'text',
            })
        })
    })
</script>
</html>